<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('检索结果列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input id="spEvtTypeId" name="params[spEvtTypeId]" style="display: none;" />
                    <input id="deptIdAndParent" name="params[deptIdAndParent]" style="display: none;" />
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>规则名称：</label>
                                <input type="text" name="params[ruleName]"/>
                            </li>
                            <li>
                                <label>事件编号：</label>
                                <input type="text" name="params[evtBh]"/>
                            </li>
                            <li>
                                <label>事件描述：</label>
                                <input type="text" name="params[contents]"/>
                            </li>
                            <li>
                                <label>办结回复：</label>
                                <input type="text" name="params[completeFeedback]"/>
                            </li>
                            <li>
                                <label>结案回复：</label>
                                <input type="text" name="params[endFeedback]"/>
                            </li>
                            <li>
                                <label>事件类型：</label>
                                <input type="text" id="evtTypeName" name="params[evtTypeName]" onclick="selectEvtTypeTree()">
                            </li>
                            <li>
                                <label>办结组织：</label>
                                <input type="text" name="params[doneDeptFullTxt]"/>
                            </li>
                            <li>
                                <label>结案组织：</label>
                                <input type="text" name="params[finishDeptFullTxt]"/>
                            </li>
                            <li>
                                <label>所属组织：</label>
                                <input type="text" name="params[ownerDeptFullTxt]"/>
                            </li>
                            <li>
                                <label>所属部门：</label>
                                <input type="text" id="deptName" name="deptName" onclick="selectDeptTree()">
                            </li>
                            <li class="select-time">
                                <label>登记时间： </label>
                                <input type="text" id="reportTimeStart" name="params[reportTimeStart]" class="time-input" placeholder="开始时间"/>
                                <span>-</span>
                                <input type="text" id="reportTimeEnd" name="params[reportTimeEnd]" class="time-input" placeholder="结束时间"/>
                            </li>
                            <li>
                                <label>数据来源：</label>
                                <select id="sourceId" name="params[sourceId]" th:with="type=${@dict.getType('evt_source')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="fullSearch()" shiro:hasPermission="system:searchResult:add">
                    <i class="fa fa-plus"></i> 全库检索
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:searchResult:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:searchResult:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:searchResult:remove')}]];
        var prefix = ctx + "system/searchResult";
        var sourceDatas= [[${@dict.getType('evt_source')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                removeUrl: prefix + "/remove",
                modalName: "检索结果",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'searchRule.ruleName',
                    title: '规则名称',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="viewSearchRule(\'' + row.searchRule.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'searchRule.evtType1.typeName',
                    title: '一级分类'
                },
                {
                    field: 'searchRule.evtType2.typeName',
                    title: '二级分类'
                },
                {
                    field: 'searchRule.evtType3.typeName',
                    title: '三级分类',
                    formatter: function(value, row, index) {
                        if(value && value.length>20){
                            return $.common.sprintf("<span>%s...</span>", value.substring(0, 20));
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'searchRule.wordToSearch',
                    title: '搜索文字'
                },
                {
                    field: 'evt.contents',
                    title: '事件描述',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'dept.deptName',
                    title: '事件所属部门'
                },
                {
                    field: 'reportTime',
                    title: '事件登记时间'
                },
                {
                    field: 'addTime',
                    title: '检索时间'
                },
                {
                    field: 'evt.sourceId',
                    title: '数据来源',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(sourceDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="viewEvt(\'' + row.evt.id + '\')"><i class="fa fa-tasks"></i> 原事件详情</a><a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 右侧弹出详情
        function viewSearchRule(rule_id){
            var url = ctx + "system/searchRule/edit/" + rule_id;
            $.modal.popupRight("检索规则信息详情", url);
        }

        // 右侧弹出详情
        function viewEvt(evt_id){
            var url = ctx + "system/evt/view/" + evt_id;
            $.modal.popupRight("事件信息详情", url);
        }

        //全库重新搜索
        function fullSearch() {
            table.set();
            $.modal.confirm("确定全库检索吗？", function() {
                var config = {
                    url: prefix + "/fullSearch",
                    type: "post",
                    dataType: "json",
                    data: {},
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.successCallback(result);
                    }
                };
                $.ajax(config);
            });
        }

        function selectEvtTypeTree() {
            var spEvtTypeId = $.common.isEmpty($("#spEvtTypeId").val()) ? "1" : $("#spEvtTypeId").val();
            var url = ctx + "system/type/selectEvtTypeTree/" + spEvtTypeId;
            var options = {
                title: '选择事件类型',
                width: "380",
                url: url,
                callBack: selectEvtTypeTreeSubmit
            };
            $.modal.openOptions(options);
        }
        function selectEvtTypeTreeSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#spEvtTypeId").val(body.find('#treeId').val());
            $("#evtTypeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
        //选择部门
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: selectDeptTreeSubmit
            };
            $.modal.openOptions(options);
        }
        function selectDeptTreeSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#deptIdAndParent").val(body.find('#treeId').val());
            $("#deptName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>